<?php
	/**
	 * 检测可以购买哪种vip
	 */
    class CheckVip extends APIBase {
		
		public $tag = "CheckVip";
		public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}

		public function logic() {
			$uid = $this->uid;
			$row = $this->mysql->select("vipdays","*",array("uid"=>$uid));
			$level = array();
			if(isset($row[0]['id']) && $row[0]['id']!=null){
				if($row[0]['level']==1 && (strtotime(date('Y-m-d',time()))-strtotime(date('Y-m-d',$row[0]['vip_time'])))/24/3600<=$row[0]['days']){
					$level[] = 2;
					$level[] = 3;
				}
				if($row[0]['level']==2 && (strtotime(date('Y-m-d',time()))-strtotime(date('Y-m-d',$row[0]['vip_time'])))/24/3600<=$row[0]['days']){
					$level[] = 3;
				}
				if($row[0]['level']==3 && (strtotime(date('Y-m-d',time()))-strtotime(date('Y-m-d',$row[0]['vip_time'])))/24/3600<=$row[0]['days']){
					$level[] = 3;
				}
				if((strtotime(date('Y-m-d',time()))-strtotime(date('Y-m-d',$row[0]['vip_time'])))/24/3600 > $row[0]['days']){
					$level = array(1,2,3);
				}
			}else{
				$level = array(1,2,3); 
			}
			$this->returnData($level);
		}
		
    	public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
